package com.hspedu.collection_;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author enomix
 * @date 2022-06-14 23:20
 */
public class CollectionFor {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        Collection col = new ArrayList();

        col.add(new Book("三国演义","罗贯中", 20));
        col.add(new Book("水浒传","施耐庵", 20));
        col.add(new Book("西游记","吴承恩", 20));

        //使用增强for迭代
        //增强for, 底层仍然是迭代器, 可以理解成简化版本的迭代器遍历
        //快捷方式: 1. I    2. col.iter     3. col.for
        for (Object book : col) {
            System.out.println("book = " + book);
        }


        //增强for,也可以直接在数组使用
        int[] nums = {1, 8, 10, 90};
        for (int num : nums) {
            System.out.println("num = " + num);
        }
    }
}
